﻿<?php

$v_deleted_exist_file_id_list=$_REQUEST['hdn_deleted_exist_file_id_list']; //Danh sach cac id file da ton tai bi xoa
$v_deleted_new_file_id_list=$_REQUEST['hdn_deleted_new_file_id_list'];  //Danh sach cac id file them moi da bi xoa

$v_ro_back=$_REQUEST['hdn_back']; 
$v_save_and_add_new=1;
$v_qa_id = 0;
//echo $v_fuseaction_back = $_REQUEST['fuseaction_back'];
//exit;
//ID cua linh vuc hoi dap
$v_cate_id = 0; 
if(isset($_REQUEST['hdn_cate_id'])){
	$v_cate_id = intval($_REQUEST['hdn_cate_id']);
}
$v_agency_id = 0;
if(isset($_REQUEST['hdn_agency_id'])){
	$v_agency_id = intval($_REQUEST['hdn_agency_id']);
}
$v_cate_type = "CATE";
if(isset($_REQUEST['cate_type'])){
	$v_cate_type = $_REQUEST['cate_type'];
}
//echo $v_cate_type; exit;
switch($v_cate_type) {
	case "CATE";
		$v_fuseaction = DISPLAY_ALL_QA_BY_ALL_CATE;
	break;
	case "IDEA";
		$v_fuseaction = DISPLAY_ALL_QA_BY_CATE;
	break;
	case "RESULT";
		$v_fuseaction = DISPLAY_ALL_QA_BY_CATE;
	break;
	case "OTHER";
		$v_fuseaction = DISPLAY_ALL_QA_BY_CATE;
	break;
	case "REGISTER";
		$v_fuseaction = DISPLAY_ALL_QA_BY_CATE;
	break;
}

//Luu trang thai hien thoi
$v_status = 0;
$v_qa_cate_id = 0;
if(isset($_REQUEST['hdn_qa_cate_id'])){
	$v_qa_cate_id = intval($_REQUEST['hdn_qa_cate_id']);
}
$v_qa_sender_name = _replace_bad_char($_REQUEST['txt_qa_sender_name']);
$v_qa_sender_address = _replace_bad_char($_REQUEST['txt_qa_send_address']);
$v_qa_sender_tel = _replace_bad_char($_REQUEST['txt_qa_send_tel']);
$v_qa_sender_email = _replace_bad_char($_REQUEST['txt_qa_send_email']);
$v_qa_sender_website = _replace_bad_char($_REQUEST['txt_qa_send_website']);
$v_qa_title = trim(_replace_bad_char($_REQUEST['txt_qa_question_title']));
$v_answerer_name = "";
$v_question_content = _replace_bad_char($_REQUEST['txt_detail']);
if($v_question_content ==""){?>
	<script>
		alert("Nội dung câu hỏi không được để trống");

		window.history.back();
	</script><?php
	exit();
}
$v_new_file_id_list="";
if(_is_sqlserver()){
	//Du lieu MSSQL
	for($i=0; $i<_CONST_MAX_NUMBER_OF_ATTACH_FILE; $i++){
		$v_form_field = 'file_attach'.$i;
		if (isset($_FILES[$v_form_field]['tmp_name'])){
			if ($v_deleted_new_file_id_list=="" Or _list_have_element($v_deleted_new_file_id_list, $i, ",")==false){
				$v_filename = _replace_bad_char(trim($_FILES[$v_form_field]['name']));
				$v_tmp_filename    = $_FILES[$v_form_field]['tmp_name'];
				$v_file_id = 0;
				if ($v_tmp_filename!="" and !is_null($v_tmp_filename)){
					_copy_file($v_tmp_filename, _CONST_LEVEL2_ATTACH_FILE_PATH_FROM_CURRENT.$v_filename);
					if ($v_new_file_id_list ==""){
						$v_new_file_id_list = _save_file_to_database('T_TEMP_FILE', 'C_FILE_NAME', 'C_FILE_CONTENT', _CONST_LEVEL2_ATTACH_FILE_PATH_FROM_CURRENT.$v_filename);
					}else{			
						$v_new_file_id_list = $v_new_file_id_list . ",". _save_file_to_database('T_TEMP_FILE', 'C_FILE_NAME', 'C_FILE_CONTENT', _CONST_LEVEL2_ATTACH_FILE_PATH_FROM_CURRENT.$v_filename);
					}	
				}	
			}	
		}	
	}
	$v_question_text_id = _save_text_to_database('T_TEMP_FILE', 'C_TEXT', $v_question_content);	
	//Cap nhat noi dung cau hoi
	$sql = "Exec Onegate_QA_QuestionSend " . $v_agency_id . "," ;
	$sql = $sql . $v_cate_id . ",'" ;
	$sql = $sql . $v_qa_sender_name . "','" ;
	$sql = $sql . $v_qa_sender_address . "','" ;
	$sql = $sql . $v_qa_sender_tel . "','" ;
	$sql = $sql . $v_qa_sender_email . "','" ;
	$sql = $sql . $v_qa_sender_website . "','";
	$sql = $sql . $v_qa_title . "'," ;
	$sql = $sql . $v_question_text_id. "," ;
	$sql = $sql . $v_status . ",'" ;
	$sql = $sql . $v_deleted_exist_file_id_list. "','" ;
	$sql = $sql . $v_new_file_id_list . "'";
	$sql = $sql . ",'".$v_answerer_name . "'";
	//echo $sql; exit;
	$ado_conn->SetFetchMode(ADODB_FETCH_ASSOC);
	$rs = $ado_conn->GetRow($sql); 
	$v_error = _replace_bad_char(trim($rs['RET_ERROR']));
	if (!is_null($v_error) and $v_error<>""){?>
		<script>
			alert("<? echo $v_error; ?>");
			if (_MODAL_DIALOG_MODE==1){
				window.location = "<? echo $v_url; ?>";
			}else{
				window.history.back();
			}	
		</script><?
		exit;
	}
}//sql
?>
<form action="index.php" method="post" name="f_back">
	<input type="hidden" name="fuseaction" value="<?php echo $v_fuseaction;?>">
	<input type="hidden" name="type_cate" value="<?php echo $v_cate_type;?>">
	<input name="hdn_deleted_new_file_id_list" type="hidden" value="<?php echo $v_deleted_new_file_id_list;?>">
	<input name="hdn_deleted_exist_file_id_list" type="hidden" value="<?php echo $v_deleted_exist_file_id_list;?>">
</form>
<Script language="javascript">
	v_url = window.location.href;
	//v_url = v_url + "?cate_type="+<?php echo $v_cate_type;?>
	//alert(v_url);
	//window.location = v_url;
	window.f_back.submit();
</Script>
